package com.ph.demo.io;

import java.io.*;

/**
 * 文件字节输入流
 */
public class ByteArrayDemo {

    public static void main(String[] args)  {
        //创建源

        File file = new File("C:\\Users\\peng\\Desktop\\1.txt");
        InputStream is = null;
        try {
            //选择流
            is = new FileInputStream(file);

            byte[] bytes  = new byte[3];

            int len = -1;

            while((len = is.read(bytes)) != -1){
                String str = new String(bytes,0,len);

                System.out.println(str);

            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            //释放资源
            if(is !=null){
                try {
                    is.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

        }


    }
}
